/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * Autogenerated by Thrift Compiler (0.10.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package org.apache.camel.component.thrift.generated;

@SuppressWarnings({ "cast", "rawtypes", "serial", "unchecked", "unused" })
/**
 * Structs are the basic complex data structures. They are comprised of fields which each have an integer identifier, a
 * type, a symbolic name, and an optional default value.
 *
 * Fields can be declared "optional", which ensures they will not be included in the serialized output if they aren't
 * set. Note that this requires some manual management in some languages.
 */
@javax.annotation.processing.Generated(value = "Autogenerated by Thrift Compiler (0.10.0)", date = "2017-06-14")
public class Work implements org.apache.thrift.TBase<Work, Work._Fields>, java.io.Serializable, Cloneable, Comparable<Work> {
    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Work");

    private static final org.apache.thrift.protocol.TField NUM1_FIELD_DESC
            = new org.apache.thrift.protocol.TField("num1", org.apache.thrift.protocol.TType.I32, (short) 1);
    private static final org.apache.thrift.protocol.TField NUM2_FIELD_DESC
            = new org.apache.thrift.protocol.TField("num2", org.apache.thrift.protocol.TType.I32, (short) 2);
    private static final org.apache.thrift.protocol.TField OP_FIELD_DESC
            = new org.apache.thrift.protocol.TField("op", org.apache.thrift.protocol.TType.I32, (short) 3);
    private static final org.apache.thrift.protocol.TField COMMENT_FIELD_DESC
            = new org.apache.thrift.protocol.TField("comment", org.apache.thrift.protocol.TType.STRING, (short) 4);

    private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new WorkStandardSchemeFactory();
    private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new WorkTupleSchemeFactory();

    public int num1; // required
    public int num2; // required
    /**
     *
     * @see Operation
     */
    public Operation op; // required
    public java.lang.String comment; // optional

    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
        NUM1((short) 1, "num1"),
        NUM2((short) 2, "num2"),
        /**
         *
         * @see Operation
         */
        OP((short) 3, "op"),
        COMMENT((short) 4, "comment");

        private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<>();

        static {
            for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) {
                byName.put(field.getFieldName(), field);
            }
        }

        /**
         * Find the _Fields constant that matches fieldId, or null if its not found.
         */
        public static _Fields findByThriftId(int fieldId) {
            switch (fieldId) {
                case 1: // NUM1
                    return NUM1;
                case 2: // NUM2
                    return NUM2;
                case 3: // OP
                    return OP;
                case 4: // COMMENT
                    return COMMENT;
                default:
                    return null;
            }
        }

        /**
         * Find the _Fields constant that matches fieldId, throwing an exception if it is not found.
         */
        public static _Fields findByThriftIdOrThrow(int fieldId) {
            _Fields fields = findByThriftId(fieldId);
            if (fields == null)
                throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!");
            return fields;
        }

        /**
         * Find the _Fields constant that matches name, or null if its not found.
         */
        public static _Fields findByName(java.lang.String name) {
            return byName.get(name);
        }

        private final short _thriftId;
        private final java.lang.String _fieldName;

        _Fields(short thriftId, java.lang.String fieldName) {
            _thriftId = thriftId;
            _fieldName = fieldName;
        }

        public short getThriftFieldId() {
            return _thriftId;
        }

        public java.lang.String getFieldName() {
            return _fieldName;
        }
    }

    // isset id assignments
    private static final int __NUM1_ISSET_ID = 0;
    private static final int __NUM2_ISSET_ID = 1;
    private byte __isset_bitfield = 0;
    private static final _Fields optionals[] = { _Fields.COMMENT };
    public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
        java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<>(_Fields.class);
        tmpMap.put(_Fields.NUM1,
                new org.apache.thrift.meta_data.FieldMetaData(
                        "num1", org.apache.thrift.TFieldRequirementType.DEFAULT,
                        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
        tmpMap.put(_Fields.NUM2,
                new org.apache.thrift.meta_data.FieldMetaData(
                        "num2", org.apache.thrift.TFieldRequirementType.DEFAULT,
                        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
        tmpMap.put(_Fields.OP,
                new org.apache.thrift.meta_data.FieldMetaData(
                        "op", org.apache.thrift.TFieldRequirementType.DEFAULT,
                        new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, Operation.class)));
        tmpMap.put(_Fields.COMMENT,
                new org.apache.thrift.meta_data.FieldMetaData(
                        "comment", org.apache.thrift.TFieldRequirementType.OPTIONAL,
                        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
        metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
        org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Work.class, metaDataMap);
    }

    public Work() {
        this.num1 = 0;

    }

    public Work(
                int num1,
                int num2,
                Operation op) {
        this();
        this.num1 = num1;
        setNum1IsSet(true);
        this.num2 = num2;
        setNum2IsSet(true);
        this.op = op;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public Work(Work other) {
        __isset_bitfield = other.__isset_bitfield;
        this.num1 = other.num1;
        this.num2 = other.num2;
        if (other.isSetOp()) {
            this.op = other.op;
        }
        if (other.isSetComment()) {
            this.comment = other.comment;
        }
    }

    public Work deepCopy() {
        return new Work(this);
    }

    @Override
    public void clear() {
        this.num1 = 0;

        setNum2IsSet(false);
        this.num2 = 0;
        this.op = null;
        this.comment = null;
    }

    public int getNum1() {
        return this.num1;
    }

    public Work setNum1(int num1) {
        this.num1 = num1;
        setNum1IsSet(true);
        return this;
    }

    public void unsetNum1() {
        __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __NUM1_ISSET_ID);
    }

    /** Returns true if field num1 is set (has been assigned a value) and false otherwise */
    public boolean isSetNum1() {
        return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __NUM1_ISSET_ID);
    }

    public void setNum1IsSet(boolean value) {
        __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __NUM1_ISSET_ID, value);
    }

    public int getNum2() {
        return this.num2;
    }

    public Work setNum2(int num2) {
        this.num2 = num2;
        setNum2IsSet(true);
        return this;
    }

    public void unsetNum2() {
        __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __NUM2_ISSET_ID);
    }

    /** Returns true if field num2 is set (has been assigned a value) and false otherwise */
    public boolean isSetNum2() {
        return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __NUM2_ISSET_ID);
    }

    public void setNum2IsSet(boolean value) {
        __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __NUM2_ISSET_ID, value);
    }

    /**
     *
     * @see Operation
     */
    public Operation getOp() {
        return this.op;
    }

    /**
     *
     * @see Operation
     */
    public Work setOp(Operation op) {
        this.op = op;
        return this;
    }

    public void unsetOp() {
        this.op = null;
    }

    /** Returns true if field op is set (has been assigned a value) and false otherwise */
    public boolean isSetOp() {
        return this.op != null;
    }

    public void setOpIsSet(boolean value) {
        if (!value) {
            this.op = null;
        }
    }

    public java.lang.String getComment() {
        return this.comment;
    }

    public Work setComment(java.lang.String comment) {
        this.comment = comment;
        return this;
    }

    public void unsetComment() {
        this.comment = null;
    }

    /** Returns true if field comment is set (has been assigned a value) and false otherwise */
    public boolean isSetComment() {
        return this.comment != null;
    }

    public void setCommentIsSet(boolean value) {
        if (!value) {
            this.comment = null;
        }
    }

    public void setFieldValue(_Fields field, java.lang.Object value) {
        switch (field) {
            case NUM1:
                if (value == null) {
                    unsetNum1();
                } else {
                    setNum1((java.lang.Integer) value);
                }
                break;

            case NUM2:
                if (value == null) {
                    unsetNum2();
                } else {
                    setNum2((java.lang.Integer) value);
                }
                break;

            case OP:
                if (value == null) {
                    unsetOp();
                } else {
                    setOp((Operation) value);
                }
                break;

            case COMMENT:
                if (value == null) {
                    unsetComment();
                } else {
                    setComment((java.lang.String) value);
                }
                break;

        }
    }

    public java.lang.Object getFieldValue(_Fields field) {
        switch (field) {
            case NUM1:
                return getNum1();

            case NUM2:
                return getNum2();

            case OP:
                return getOp();

            case COMMENT:
                return getComment();

        }
        throw new java.lang.IllegalStateException();
    }

    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
    public boolean isSet(_Fields field) {
        if (field == null) {
            throw new java.lang.IllegalArgumentException();
        }

        switch (field) {
            case NUM1:
                return isSetNum1();
            case NUM2:
                return isSetNum2();
            case OP:
                return isSetOp();
            case COMMENT:
                return isSetComment();
        }
        throw new java.lang.IllegalStateException();
    }

    @Override
    public boolean equals(java.lang.Object that) {
        if (that == null)
            return false;
        if (that instanceof Work)
            return this.equals((Work) that);
        return false;
    }

    public boolean equals(Work that) {
        if (that == null)
            return false;
        if (this == that)
            return true;

        boolean this_present_num1 = true;
        boolean that_present_num1 = true;
        if (this_present_num1 || that_present_num1) {
            if (!(this_present_num1 && that_present_num1))
                return false;
            if (this.num1 != that.num1)
                return false;
        }

        boolean this_present_num2 = true;
        boolean that_present_num2 = true;
        if (this_present_num2 || that_present_num2) {
            if (!(this_present_num2 && that_present_num2))
                return false;
            if (this.num2 != that.num2)
                return false;
        }

        boolean this_present_op = true && this.isSetOp();
        boolean that_present_op = true && that.isSetOp();
        if (this_present_op || that_present_op) {
            if (!(this_present_op && that_present_op))
                return false;
            if (!this.op.equals(that.op))
                return false;
        }

        boolean this_present_comment = true && this.isSetComment();
        boolean that_present_comment = true && that.isSetComment();
        if (this_present_comment || that_present_comment) {
            if (!(this_present_comment && that_present_comment))
                return false;
            if (!this.comment.equals(that.comment))
                return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int hashCode = 1;

        hashCode = hashCode * 8191 + num1;

        hashCode = hashCode * 8191 + num2;

        hashCode = hashCode * 8191 + ((isSetOp()) ? 131071 : 524287);
        if (isSetOp())
            hashCode = hashCode * 8191 + op.getValue();

        hashCode = hashCode * 8191 + ((isSetComment()) ? 131071 : 524287);
        if (isSetComment())
            hashCode = hashCode * 8191 + comment.hashCode();

        return hashCode;
    }

    @Override
    public int compareTo(Work other) {
        if (!getClass().equals(other.getClass())) {
            return getClass().getName().compareTo(other.getClass().getName());
        }

        int lastComparison = 0;

        lastComparison = java.lang.Boolean.valueOf(isSetNum1()).compareTo(other.isSetNum1());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetNum1()) {
            lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.num1, other.num1);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = java.lang.Boolean.valueOf(isSetNum2()).compareTo(other.isSetNum2());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetNum2()) {
            lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.num2, other.num2);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = java.lang.Boolean.valueOf(isSetOp()).compareTo(other.isSetOp());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetOp()) {
            lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.op, other.op);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = java.lang.Boolean.valueOf(isSetComment()).compareTo(other.isSetComment());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetComment()) {
            lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.comment, other.comment);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        return 0;
    }

    public _Fields fieldForId(int fieldId) {
        return _Fields.findByThriftId(fieldId);
    }

    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
        scheme(iprot).read(iprot, this);
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
        scheme(oprot).write(oprot, this);
    }

    @Override
    public java.lang.String toString() {
        java.lang.StringBuilder sb = new java.lang.StringBuilder("Work(");
        boolean first = true;

        sb.append("num1:");
        sb.append(this.num1);
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("num2:");
        sb.append(this.num2);
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("op:");
        if (this.op == null) {
            sb.append("null");
        } else {
            sb.append(this.op);
        }
        first = false;
        if (isSetComment()) {
            if (!first)
                sb.append(", ");
            sb.append("comment:");
            if (this.comment == null) {
                sb.append("null");
            } else {
                sb.append(this.comment);
            }
            first = false;
        }
        sb.append(")");
        return sb.toString();
    }

    public void validate() {
        // check for required fields
        // check for sub-struct validity
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
        try {
            write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
        } catch (org.apache.thrift.TException te) {
            throw new java.io.IOException(te);
        }
    }

    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
        try {
            // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
            __isset_bitfield = 0;
            read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
        } catch (org.apache.thrift.TException te) {
            throw new java.io.IOException(te);
        }
    }

    private static class WorkStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
        public WorkStandardScheme getScheme() {
            return new WorkStandardScheme();
        }
    }

    private static class WorkStandardScheme extends org.apache.thrift.scheme.StandardScheme<Work> {

        public void read(org.apache.thrift.protocol.TProtocol iprot, Work struct) throws org.apache.thrift.TException {
            org.apache.thrift.protocol.TField schemeField;
            iprot.readStructBegin();
            while (true) {
                schemeField = iprot.readFieldBegin();
                if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
                    break;
                }
                switch (schemeField.id) {
                    case 1: // NUM1
                        if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                            struct.num1 = iprot.readI32();
                            struct.setNum1IsSet(true);
                        } else {
                            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                        }
                        break;
                    case 2: // NUM2
                        if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                            struct.num2 = iprot.readI32();
                            struct.setNum2IsSet(true);
                        } else {
                            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                        }
                        break;
                    case 3: // OP
                        if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                            struct.op = org.apache.camel.component.thrift.generated.Operation.findByValue(iprot.readI32());
                            struct.setOpIsSet(true);
                        } else {
                            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                        }
                        break;
                    case 4: // COMMENT
                        if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
                            struct.comment = iprot.readString();
                            struct.setCommentIsSet(true);
                        } else {
                            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                        }
                        break;
                    default:
                        org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                }
                iprot.readFieldEnd();
            }
            iprot.readStructEnd();

            // check for required fields of primitive type, which can't be checked in the validate method
            struct.validate();
        }

        public void write(org.apache.thrift.protocol.TProtocol oprot, Work struct) throws org.apache.thrift.TException {
            struct.validate();

            oprot.writeStructBegin(STRUCT_DESC);
            oprot.writeFieldBegin(NUM1_FIELD_DESC);
            oprot.writeI32(struct.num1);
            oprot.writeFieldEnd();
            oprot.writeFieldBegin(NUM2_FIELD_DESC);
            oprot.writeI32(struct.num2);
            oprot.writeFieldEnd();
            if (struct.op != null) {
                oprot.writeFieldBegin(OP_FIELD_DESC);
                oprot.writeI32(struct.op.getValue());
                oprot.writeFieldEnd();
            }
            if (struct.comment != null) {
                if (struct.isSetComment()) {
                    oprot.writeFieldBegin(COMMENT_FIELD_DESC);
                    oprot.writeString(struct.comment);
                    oprot.writeFieldEnd();
                }
            }
            oprot.writeFieldStop();
            oprot.writeStructEnd();
        }

    }

    private static class WorkTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
        public WorkTupleScheme getScheme() {
            return new WorkTupleScheme();
        }
    }

    private static class WorkTupleScheme extends org.apache.thrift.scheme.TupleScheme<Work> {

        @Override
        public void write(org.apache.thrift.protocol.TProtocol prot, Work struct) throws org.apache.thrift.TException {
            org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
            java.util.BitSet optionals = new java.util.BitSet();
            if (struct.isSetNum1()) {
                optionals.set(0);
            }
            if (struct.isSetNum2()) {
                optionals.set(1);
            }
            if (struct.isSetOp()) {
                optionals.set(2);
            }
            if (struct.isSetComment()) {
                optionals.set(3);
            }
            oprot.writeBitSet(optionals, 4);
            if (struct.isSetNum1()) {
                oprot.writeI32(struct.num1);
            }
            if (struct.isSetNum2()) {
                oprot.writeI32(struct.num2);
            }
            if (struct.isSetOp()) {
                oprot.writeI32(struct.op.getValue());
            }
            if (struct.isSetComment()) {
                oprot.writeString(struct.comment);
            }
        }

        @Override
        public void read(org.apache.thrift.protocol.TProtocol prot, Work struct) throws org.apache.thrift.TException {
            org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
            java.util.BitSet incoming = iprot.readBitSet(4);
            if (incoming.get(0)) {
                struct.num1 = iprot.readI32();
                struct.setNum1IsSet(true);
            }
            if (incoming.get(1)) {
                struct.num2 = iprot.readI32();
                struct.setNum2IsSet(true);
            }
            if (incoming.get(2)) {
                struct.op = org.apache.camel.component.thrift.generated.Operation.findByValue(iprot.readI32());
                struct.setOpIsSet(true);
            }
            if (incoming.get(3)) {
                struct.comment = iprot.readString();
                struct.setCommentIsSet(true);
            }
        }
    }

    private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
        return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme())
                ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
    }
}
